//
//  AIFUserCenterManager.m
//  PywSdk
//
//  Created by smallwave on 16/4/12.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFUserCenterManager.h"

@implementation AIFUserCenterManager

NSString *const UserCenter_ACCOUNT = @"account";
NSString *const UserCenter_GameId = @"gameid";
NSString *const UserCenter_Tid = @"tid";
NSString *const UserCenter_Sign = @"sign";
NSString *const UserCenter_Passport = @"passport";
NSString *const UserCenter_PassportToken = @"passport_token";
NSString *const UserCenter_Token = @"token";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName{
    return URL_USERCENTER;
}

- (ETAPIManagerRequestType)requestType{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType{
    return [PywAppInfo sharedAppInfo].seriviceType;
}


#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    
    NSString * gameid = [PywAppInfo sharedAppInfo].gameId;
    NSString * passport = [PywPlatformMain sharedPlatformMain].passport;
    NSString * account = [PywPlatformMain sharedPlatformMain].account;
    
    NSString * tid = [PywAppInfo sharedAppInfo].tid;
    NSString * apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString * sign = [PywCipherUtils md5:[NSString stringWithFormat:@"%@%@",account,apiSecret2]];
    
    NSString * passport_Token = [PywPlatformMain sharedPlatformMain].passport_Token;
    NSString * token = [PywPlatformMain sharedPlatformMain].token;
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    [param setObject:account forKey:UserCenter_ACCOUNT];
    [param setObject:gameid forKey:UserCenter_GameId];
    [param setObject:tid forKey:UserCenter_Tid];
    [param setObject:sign forKey:UserCenter_Sign];
    if ([PywPlatformMain sharedPlatformMain].accountType == UserType_Passport) {
        [param setObject:passport forKey:UserCenter_Passport];
        [param setObject:passport_Token forKey:UserCenter_PassportToken];
    }else{
        [param setObject:@"" forKey:UserCenter_Passport];
        [param setObject:token forKey:UserCenter_Token];
    }
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}

@end
